package spotGUI.personalProfileGUI;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import java.awt.Dimension;
import java.util.ResourceBundle;

public class ProfileUpdateLogger extends JDialog {


	
	private final JPanel contentPanel = new JPanel();

	private JTextPane textPane;
	private Document doc;
	private JLabel lblTitle ;
	private JLabel lblTitle2;
	private JScrollPane scrollPane;
	
	private int count = 0;
	private JLabel lblImage;
	private JLabel lblDescription;
	
	public ProfileUpdateLogger() {
		
		super();
		
		setTitle(ResourceBundle.getBundle("spotGUI.personalProfileGUI.messages").getString("ProfileUpdateLogger.this.title")); //$NON-NLS-1$ //$NON-NLS-2$
		setMinimumSize(new Dimension(430, 200));
		setSize(new Dimension(430, 350));
		setLocationRelativeTo(null);
		setVisible(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
		gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0};
		gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		
		lblImage = new JLabel("");
		lblImage.setIcon(new ImageIcon(ProfileUpdateLogger.class.getResource("/images/Icons/64x64px/warning.png")));
		GridBagConstraints gbc_lblImage = new GridBagConstraints();
		gbc_lblImage.gridheight = 2;
		gbc_lblImage.insets = new Insets(0, 0, 5, 5);
		gbc_lblImage.gridx = 0;
		gbc_lblImage.gridy = 0;
		contentPanel.add(lblImage, gbc_lblImage);

		lblTitle = new JLabel(ResourceBundle.getBundle("spotGUI.personalProfileGUI.messages").getString("ProfileUpdateLogger.lblTitle.text")); //$NON-NLS-1$ //$NON-NLS-2$
		lblTitle.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 16));
		GridBagConstraints gbc_lblTitle = new GridBagConstraints();
		gbc_lblTitle.fill = GridBagConstraints.VERTICAL;
		gbc_lblTitle.anchor = GridBagConstraints.WEST;
		gbc_lblTitle.insets = new Insets(0, 0, 5, 0);
		gbc_lblTitle.gridx = 1;
		gbc_lblTitle.gridy = 0;
		contentPanel.add(lblTitle, gbc_lblTitle);

		lblTitle2 = new JLabel(ResourceBundle.getBundle("spotGUI.personalProfileGUI.messages").getString("ProfileUpdateLogger.lblTitle2.text")); //$NON-NLS-1$ //$NON-NLS-2$
		lblTitle2.setForeground(Color.RED.darker().darker());
		lblTitle2.setFont(new Font("Agency FB", Font.BOLD, 31));
		GridBagConstraints gbc_lblTitle2 = new GridBagConstraints();
		gbc_lblTitle2.insets = new Insets(0, 0, 5, 0);
		gbc_lblTitle2.fill = GridBagConstraints.BOTH;
		gbc_lblTitle2.gridx = 1;
		gbc_lblTitle2.gridy = 1;
		contentPanel.add(lblTitle2, gbc_lblTitle2);
		
		lblDescription = new JLabel(ResourceBundle.getBundle("spotGUI.personalProfileGUI.messages").getString("ProfileUpdateLogger.lblDescription.text")); //$NON-NLS-1$ //$NON-NLS-2$
		lblDescription.setFont(new Font("Dialog", Font.PLAIN, 11));
		GridBagConstraints gbc_lblDescription = new GridBagConstraints();
		gbc_lblDescription.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblDescription.insets = new Insets(0, 0, 5, 0);
		gbc_lblDescription.gridx = 1;
		gbc_lblDescription.gridy = 2;
		contentPanel.add(lblDescription, gbc_lblDescription);

		scrollPane = new JScrollPane();
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setOpaque(false);
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 1;
		gbc_scrollPane.gridy = 3;
		contentPanel.add(scrollPane, gbc_scrollPane);

		textPane = new JTextPane();
		textPane.setEditable(false);
		doc = textPane.getDocument();
		textPane.setOpaque(false);
		scrollPane.setViewportView(textPane);
	}

	public void addError (String error) {
		count++;
		try {
			doc.insertString(doc.getLength(), count+". "+error+"\n", null);
		} catch (BadLocationException e) {
			// do nothing
			e.printStackTrace();
		}
		
		setVisible(true);
	}
	
	public void putOnTop () {
		toFront();
	}
	
	public void clear () {
		count = 0;
		textPane.setText("");
	}
}
